<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>将数字12345678转化成RMB形式：12,345,678</title>
    <style type="text/css">
        .container {
            width: 100vw;
            height: 100vh;
            display: flex;
            flex-direction: column;
        }
    </style>
</head>

<body>
    <div class="container">
        <button id="btn">获取计算结果</button>
    </div>
    <script type="text/javascript">
        //思路就是：首先字符串转数组  数组翻转  然后数组遍历 %3 ===0就加个逗号  
        function shiftData(rmb) {
            let rmbArr = rmb.split("").reverse()
            let res = []
            for(let i=0;i<rmbArr.length;i++){
                 res.push(rmbArr[i])
                 if((i+1)%3===0){
                      res.push(',')
                 }
            }
            return res.reverse().join("")
        }
        console.log(btn.innerText)
        btn.addEventListener('click', function () {
            var rmb = '1678'
            const rmbResult = shiftData(rmb)
            console.log(rmbResult)
        })
    </script>
</body>

</html>